// $ANTLR : "AnasintModif.g" -> "AnasintModif.java"$

package pl.prac05;

import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.ANTLRException;
import antlr.LLkParser;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.MismatchedTokenException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;

public class AnasintModif extends antlr.LLkParser       implements AnasintModifTokenTypes
 {

protected AnasintModif(TokenBuffer tokenBuf, int k) {
  super(tokenBuf,k);
  tokenNames = _tokenNames;
}

public AnasintModif(TokenBuffer tokenBuf) {
  this(tokenBuf,3);
}

protected AnasintModif(TokenStream lexer, int k) {
  super(lexer,k);
  tokenNames = _tokenNames;
}

public AnasintModif(TokenStream lexer) {
  this(lexer,3);
}

public AnasintModif(ParserSharedInputState state) {
  super(state,3);
  tokenNames = _tokenNames;
}

	public final void entrada() throws RecognitionException, TokenStreamException {
		
		
		declaraciones();
		match(SECCION);
		regla();
		match(SECCION);
		usercode();
	}
	
	public final void declaraciones() throws RecognitionException, TokenStreamException {
		
		
		match(DIGIT);
		regexp1();
		match(LETTER);
		regexp2();
		cdefinitions();
	}
	
	public final void regla() throws RecognitionException, TokenStreamException {
		
		
		reglaexp1();
		action();
		match(SEMICOLON);
		reglaexp2();
		action();
		match(SEMICOLON);
	}
	
	public final void usercode() throws RecognitionException, TokenStreamException {
		
		
		match(INT);
		function_def();
		match(INT);
		function_def();
	}
	
	public final void regexp1() throws RecognitionException, TokenStreamException {
		
		
		match(CORCHETE_ABRIR);
		match(NUM_INTEGER);
		match(MENOS);
		match(NUM_INTEGER);
		match(CORCHETE_CERRAR);
	}
	
	public final void regexp2() throws RecognitionException, TokenStreamException {
		
		
		match(CORCHETE_ABRIR);
		match(ID);
		match(MENOS);
		match(ID);
		match(MENOS);
		match(ID);
		match(CORCHETE_CERRAR);
	}
	
	public final void cdefinitions() throws RecognitionException, TokenStreamException {
		
		
		match(PERCENT);
		match(LLAVE_ABRIR);
		{
		cdefinition();
		}
		match(PERCENT);
		match(LLAVE_CERRAR);
	}
	
	public final void cdefinition() throws RecognitionException, TokenStreamException {
		
		
		tipo();
		match(ID);
		match(SEMICOLON);
		tipo();
		match(ID);
		match(SEMICOLON);
	}
	
	public final void tipo() throws RecognitionException, TokenStreamException {
		
		
		switch ( LA(1)) {
		case INT:
		{
			match(INT);
			break;
		}
		case CHAR:
		{
			match(CHAR);
			break;
		}
		case FLOAT:
		{
			match(FLOAT);
			break;
		}
		case DOUBLE:
		{
			match(DOUBLE);
			break;
		}
		case STRING:
		{
			match(STRING);
			break;
		}
		case VOID:
		{
			match(VOID);
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
	}
	
	public final void reglaexp1() throws RecognitionException, TokenStreamException {
		
		
		letras();
		match(PARENTESIS_ABRIR);
		letras();
		match(OR);
		digitos();
		match(PARENTESIS_CERRAR);
		match(ASTERISCO);
	}
	
	public final void action() throws RecognitionException, TokenStreamException {
		
		
		match(ID);
		match(INC);
	}
	
	public final void reglaexp2() throws RecognitionException, TokenStreamException {
		
		
		digitos();
		match(MAS);
	}
	
	public final void letras() throws RecognitionException, TokenStreamException {
		
		
		match(LLAVE_ABRIR);
		match(LETTER);
		match(LLAVE_CERRAR);
	}
	
	public final void digitos() throws RecognitionException, TokenStreamException {
		
		
		match(LLAVE_ABRIR);
		match(DIGIT);
		match(LLAVE_CERRAR);
	}
	
	public final void acciones() throws RecognitionException, TokenStreamException {
		
		
		{
		if ((LA(1)==ID) && (LA(2)==ASIGNACION)) {
			asignacion();
		}
		else if ((LA(1)==ID) && (LA(2)==INC||LA(2)==DEC)) {
			incdec();
		}
		else if ((LA(1)==RETURN)) {
			match(RETURN);
			{
			switch ( LA(1)) {
			case ID:
			{
				match(ID);
				break;
			}
			case NUM_INTEGER:
			{
				match(NUM_INTEGER);
				break;
			}
			case TRUE:
			{
				match(TRUE);
				break;
			}
			case FALSE:
			{
				match(FALSE);
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
			}
		}
		else if ((LA(1)==ID) && (LA(2)==PARENTESIS_ABRIR)) {
			function_statement();
		}
		else {
			throw new NoViableAltException(LT(1), getFilename());
		}
		
		}
		match(SEMICOLON);
	}
	
	public final void asignacion() throws RecognitionException, TokenStreamException {
		
		
		match(ID);
		match(ASIGNACION);
		valor();
	}
	
	public final void incdec() throws RecognitionException, TokenStreamException {
		
		
		match(ID);
		{
		switch ( LA(1)) {
		case INC:
		{
			match(INC);
			break;
		}
		case DEC:
		{
			match(DEC);
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		}
	}
	
	public final void function_statement() throws RecognitionException, TokenStreamException {
		
		
		match(ID);
		match(PARENTESIS_ABRIR);
		{
		switch ( LA(1)) {
		case ID:
		case CADENA:
		{
			params_statement();
			break;
		}
		case PARENTESIS_CERRAR:
		{
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		}
		match(PARENTESIS_CERRAR);
	}
	
	public final void valor() throws RecognitionException, TokenStreamException {
		
		
		switch ( LA(1)) {
		case NUM_INTEGER:
		{
			match(NUM_INTEGER);
			break;
		}
		case NUM_REAL:
		{
			match(NUM_REAL);
			break;
		}
		case CADENA:
		{
			match(CADENA);
			break;
		}
		case ID:
		{
			function_statement();
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
	}
	
	public final void params_statement() throws RecognitionException, TokenStreamException {
		
		
		param_stat();
		{
		_loop972:
		do {
			if ((LA(1)==COMA)) {
				match(COMA);
				param_stat();
			}
			else {
				break _loop972;
			}
			
		} while (true);
		}
	}
	
	public final void param_stat() throws RecognitionException, TokenStreamException {
		
		
		switch ( LA(1)) {
		case ID:
		{
			match(ID);
			{
			switch ( LA(1)) {
			case CORCHETE_ABRIR:
			{
				match(CORCHETE_ABRIR);
				match(NUM_INTEGER);
				match(CORCHETE_CERRAR);
				break;
			}
			case COMA:
			case PARENTESIS_CERRAR:
			{
				break;
			}
			default:
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			}
			}
			break;
		}
		case CADENA:
		{
			match(CADENA);
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
	}
	
	public final void function_def() throws RecognitionException, TokenStreamException {
		
		
		match(ID);
		match(PARENTESIS_ABRIR);
		{
		if (((LA(1) >= VOID && LA(1) <= STRING)) && (LA(2)==ID||LA(2)==ASTERISCO)) {
			params_def();
		}
		else if ((LA(1)==VOID) && (LA(2)==PARENTESIS_CERRAR)) {
			match(VOID);
		}
		else if ((LA(1)==PARENTESIS_CERRAR)) {
		}
		else {
			throw new NoViableAltException(LT(1), getFilename());
		}
		
		}
		match(PARENTESIS_CERRAR);
		match(LLAVE_ABRIR);
		{
		int _cnt979=0;
		_loop979:
		do {
			if ((LA(1)==RETURN||LA(1)==ID)) {
				acciones();
			}
			else {
				if ( _cnt979>=1 ) { break _loop979; } else {throw new NoViableAltException(LT(1), getFilename());}
			}
			
			_cnt979++;
		} while (true);
		}
		match(LLAVE_CERRAR);
	}
	
	public final void params_def() throws RecognitionException, TokenStreamException {
		
		
		def_par();
		{
		_loop982:
		do {
			if ((LA(1)==COMA)) {
				match(COMA);
				def_par();
			}
			else {
				break _loop982;
			}
			
		} while (true);
		}
	}
	
	public final void def_par() throws RecognitionException, TokenStreamException {
		
		
		tipo();
		{
		switch ( LA(1)) {
		case ASTERISCO:
		{
			match(ASTERISCO);
			break;
		}
		case ID:
		{
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		}
		match(ID);
		{
		switch ( LA(1)) {
		case CORCHETE_ABRIR:
		{
			match(CORCHETE_ABRIR);
			match(CORCHETE_CERRAR);
			break;
		}
		case COMA:
		case PARENTESIS_CERRAR:
		{
			break;
		}
		default:
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		}
		}
	}
	
	
	public static final String[] _tokenNames = {
		"<0>",
		"EOF",
		"<2>",
		"NULL_TREE_LOOKAHEAD",
		"NUM_REAL",
		"NUM_INTEGER",
		"\"void\"",
		"\"int\"",
		"\"char\"",
		"\"float\"",
		"\"double\"",
		"\"string\"",
		"\"true\"",
		"\"false\"",
		"\"if\"",
		"\"while\"",
		"\"for\"",
		"\"do\"",
		"\"return\"",
		"\"#include\"",
		"\"top\"",
		"\"%option noyywrap\"",
		"\"digit\"",
		"\"letter\"",
		"NUEVA_LINEA",
		"BLANCO",
		"DIGITO",
		"NUMERO",
		"LETRA",
		"ID",
		"CADENA",
		"COMILLAS",
		"PERCENT",
		"SECCION",
		"PUNTO",
		"COLON",
		"SEMICOLON",
		"COMA",
		"ASIGNACION",
		"PARENTESIS_ABRIR",
		"PARENTESIS_CERRAR",
		"LLAVE_ABRIR",
		"LLAVE_CERRAR",
		"CORCHETE_ABRIR",
		"CORCHETE_CERRAR",
		"MENOR",
		"MAYOR",
		"NEGACION",
		"NO_IGUAL",
		"MENOR_IGUAL",
		"MAYOR_IGUAL",
		"QUESTION",
		"AMP",
		"MAS",
		"MENOS",
		"ASTERISCO",
		"DIV",
		"OR",
		"INC",
		"DEC",
		"COMENTARIO"
	};
	
	
	}
